package com.azt.utils;

import com.azt.exception.ServiceException;

/**
 * 异常抛出
 * Created by LiQZ on 2017/3/30.
 */
public class Preconditions {

    public static <T> T checkNotNull(T reference) {
        if(reference == null) {
            throw new ServiceException(400, "NullPointException");
        } else {
            return reference;
        }
    }

    public static <T> T checkNotNull(T reference, Object errorMessage) {
        if(reference == null) {
            throw new ServiceException(400, String.valueOf(errorMessage));
        } else {
            return reference;
        }
    }

    public static void checkArgument(boolean expression) {
        if(!expression) {
            throw new ServiceException(400, "IllegalArgumentException");
        }
    }

    public static void checkArgument(boolean expression, Object errorMessage) {
        if(!expression) {
            throw new ServiceException(400, String.valueOf(errorMessage));
        }
    }



}
